package com.kate.mall.common.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Description: 装饰者模式
 * @Auther: 新梦想*陈超
 * @Date: 2021/10/11 09:04
 */
@WebFilter(urlPatterns = "/*")
@Slf4j
public class XssFilter implements Filter {
    // J2EE Servlet标准  不同服务器厂商实现不一样
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("-------->开始进行Xss过滤----------");
        //Enumeration<String> parameterNames = servletRequest.getParameterNames();
        //TODO 1.获取原始的request对象
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        //TODO 2.根据原始的request对象，得到增强的request对象(是一个request装饰者，而不是request子类)
        XssServletRequest wrapper=new XssServletRequest(request);
        //TODO 3.将新的request传递给后面拦截器，controller
        filterChain.doFilter(wrapper, servletResponse);

    }
}
//class TOmcatservletRequest extends ServletRequest{
//
//}
//
//class JettyservletRequest extends ServletRequest{
//
//}




